<?php
/**
 * SocialEngine
 *
 * @category   Application_Widget
 * @package    Translator
 * @copyright  Copyright 2008-2011 NewroSoftMods and TaurusSoft
 * @license    http://www.socialengine.net/license/
 * @author     Bezugliy Sergey
 */
?>

<script type="text/javascript">
function googleTranslateElementInit() {
  new google.translate.TranslateElement({
    //pageLanguage: 'en',
    //includedLanguages: 'en,de,ru,uk,fr,es',
    multilanguagePage: true,
    layout: google.translate.TranslateElement.InlineLayout.SIMPLE
  }, 'google_translate_element');
}

function include_script(url) {
  var script = document.createElement('script');
  script.setAttribute('type', 'text/javascript')
  script.setAttribute('src', url);
  document.getElementsByTagName('head').item(0).appendChild(script);
}

window.addEvent('load', function() {
    // is set translator
    if ($('google_translate_element')) {
        return;
    }
    
    // get this conteiner
    var thisConteiner = $$('div.layout_translator_translator_google_global');
    if (thisConteiner.length > 1) {
        thisConteiner = thisConteiner[0];
    }
    
    // main element
    var mainElement;
    
    // get location
    if (thisConteiner.getParent().getParent().get('class') == 'layout_page_header') {
        var elType;
        if ($('core_menu_mini_menu')) {
            // integre to menu mini
            mainElement = $('core_menu_mini_menu').getElement('ul').getElement('li');
            elType = 'li';
        } else {
            // integre to header
            mainElement = $('global_header').getElement('.layout_main');
            elType = 'div';
        }
        
        var google_translate_element = new Element(elType, {
            id : 'google_translate_element',
        });
        
        google_translate_element.inject(mainElement, 'before');
    } else {
        if ($('global_footer').getElement('.layout_core_menu_footer')) {
            mainElement = $('global_footer').getElement('.layout_core_menu_footer');
        } else {
            mainElement = $('global_footer').getElement('.layout_main');
        }
        
        var google_translate_element = new Element('div', {
            id : 'google_translate_element',
        });
        
        google_translate_element.inject(mainElement);
    }
    
    include_script('http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit');
});
</script>

<style type="text/css">
.goog-te-gadget a {
    color: #999 !important;
    text-decoration: none;
}

.goog-te-gadget img {
    display: none;
}

.goog-te-gadget-simple {
    border: 1px solid #DDD;
    border-radius: 3px;
}

.goog-te-menu-value span {
    border: none !important;
}

.goog-te-menu-value span {
    display: none;
}

.goog-te-menu-value span:first-child,
.goog-te-menu-value span:last-child {
    display: inline;
}

.goog-te-menu-value span:first-child {
    margin-right: 3px;
}

#global_header div#google_translate_element {
    position: absolute;
    top: 5px;
    right: 7px;
}

#global_footer #google_translate_element {
    display: inline-block;
    margin-left: 7px;
}
</style>